package com.huike.web.controller.clues;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.dto.TbClueDTO;
import com.huike.clues.domain.vo.AssignmentVo;
import com.huike.clues.service.impl.TbClueServiceImpl;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import org.apache.catalina.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.huike.common.utils.SecurityUtils.getUserId;

/**
 * 线索管理Controller
 *
 * @date 2023-04-02
 */
@RestController
@RequestMapping("/clues/clue")
public class TbClueController extends BaseController {
    @Autowired
    private TbClueServiceImpl tbClueService;

    /**
     * 分页查询线索
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(TbClueDTO dto) {
        startPage();
        List<TbClue> byId = tbClueService.selectById(dto);
        return getDataTable(byId);
    }

    /**
     * 分页查询线索池
     * @param dto
     * @return
     */
    @GetMapping("/pool")
    public TableDataInfo pool(TbClueDTO dto) {
        startPage();
        List<TbClue> byId = tbClueService.selectpool(dto);
        return getDataTable(byId);
    }

    /**
     * 新增线索
     * @param dto
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody TbClueDTO dto) {
        TbClue clue = new TbClue();
        // 先复制属性，再设置特定值
        dto.setFalseCount(2);
        //获取当前的登陆人id
        dto.setUserId(getUserId());
        BeanUtils.copyProperties(dto, clue);

        tbClueService.save(clue);
        return AjaxResult.success();
    }
    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public AjaxResult selectbyid(@PathVariable Integer id){
        TbClue byId = tbClueService.getById(id);
        return AjaxResult.success(byId);
    }

    /**
     * 修改线索管理
     * @param dto
     * @return
     */
    @PutMapping
    public AjaxResult update(@RequestBody TbClueDTO dto){
        tbClueService.lambdaUpdate().eq(TbClue::getId,dto.getId());
        return success();

    }

    /**
     * 批量分配
     * @param assignmentVo
     * @return
     */
    @PutMapping("/assignment")
    public AjaxResult assignment(AssignmentVo assignmentVo){
       /* tbClueService.update(assignmentVo)*/
        return success();
    }
}
